package com.chestnut.contentcore.controller;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chestnut.common.log.annotation.Log;
import com.chestnut.common.log.enums.BusinessType;
import com.chestnut.common.security.web.PageRequest;
import com.chestnut.contentcore.domain.CmsCertificationsStandards;
import com.chestnut.contentcore.domain.CmsCompanyConfiguration;

import com.chestnut.contentcore.service.ICmsCompanyConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chestnut.common.security.web.BaseRestController;

import com.chestnut.common.security.anno.Priv;
import lombok.RequiredArgsConstructor;
import com.chestnut.common.domain.R;

/**
 * 公司联系人介绍配置Controller
 *
 * @author chestnut
 * @date 2025-04-27
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/configuration")
public class CmsCompanyConfigurationController extends BaseRestController {

    @Autowired
    private ICmsCompanyConfigurationService cmsCompanyConfigurationService;

    /**
     * 查询公司联系人介绍配置列表
     */
//    @Priv
    @GetMapping("/list")
    public R<?> list(CmsCompanyConfiguration cmsCompanyConfiguration)
    {
        PageRequest pr = this.getPageRequest();
        LambdaQueryChainWrapper<CmsCompanyConfiguration> wrapper = this.cmsCompanyConfigurationService.lambdaQuery();
                    if (cmsCompanyConfiguration.getTypeName() != null) {
                        wrapper.like(CmsCompanyConfiguration::getTypeName,cmsCompanyConfiguration.getTypeName());
                    }
                    if (cmsCompanyConfiguration.getContent() != null) {
                        wrapper.like(CmsCompanyConfiguration::getContent,cmsCompanyConfiguration.getContent());
                    }
        if (cmsCompanyConfiguration.getLanguage() != null) {
            wrapper.like(CmsCompanyConfiguration::getLanguage,cmsCompanyConfiguration.getLanguage());
        }
        wrapper.orderByAsc(CmsCompanyConfiguration::getSort);
        Page<CmsCompanyConfiguration> page = wrapper
                .page(new Page<>(pr.getPageNumber(), pr.getPageSize(), true));

        return this.bindDataTable(page);
    }

    /**
     * 获取公司联系人介绍配置详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:configuration:query')")
    @GetMapping(value = "/{id}")
    public R<?> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(this.cmsCompanyConfigurationService.getById(id));
    }

    /**
     * 新增公司联系人介绍配置
     */
//    @Priv
//    @Log(title = "公司联系人介绍配置", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody CmsCompanyConfiguration cmsCompanyConfiguration)
    {
        this.cmsCompanyConfigurationService.save(cmsCompanyConfiguration);
        return R.ok();
    }

    /**
     * 修改公司联系人介绍配置
     */
//    @Priv
    @Log(title = "公司联系人介绍配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody CmsCompanyConfiguration cmsCompanyConfiguration)
    {
        this.cmsCompanyConfigurationService.updateById(cmsCompanyConfiguration);
        return R.ok();
    }

    /**
     * 删除公司联系人介绍配置
     */
//    @Priv
    @Log(title = "公司联系人介绍配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R<?> remove(@PathVariable Long[] ids)
    {
        this.cmsCompanyConfigurationService.removeBatchByIds(List.of(ids));
        return R.ok();
    }
}
